﻿namespace CoverageRunner.Core;

/// <summary>
/// OpenCppCoverage 的执行器实现
/// </summary>
public class OccRunner: ICoverageRunner
{
    private RunnerConfig? _config;
    public void Initialize(RunnerConfig config)
    {
        _config = config;
    }

    public string GetCommandLine()
    {
        CheckConfig();

        return "";
    }

    public void OpenCoverageReport(ICoverageRunner.OpenType openType)
    {
        CheckConfig();

        switch (openType)
        {
            case ICoverageRunner.OpenType.Explorer:
                CommonTools.ShowFileInExplorer(Path.Combine(_config!.ReportDirectory, "index.html"));
                break;
            case ICoverageRunner.OpenType.Browser:
                CommonTools.OpenHtml(Path.Combine(_config!.ReportDirectory, "index.html"));
                break;
            default:
                throw new ArgumentOutOfRangeException(nameof(openType), openType, null);
        }
    }

    public void Run()
    {
        throw new NotImplementedException();
    }

    private void CheckConfig()
    {
        if (_config == null)
        {
            throw new InvalidOperationException("No config set!!");
        }
    }

    public string Id => RunnerIds.OpenCppCoverage;
}